package TokenRecognizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
public class AFDSimulator {

    public boolean simulate(String s, Automata tautomata){
        Integer index = 0;
        boolean is = false;
        boolean found = false;
        Integer actState = 0;
        Integer states = 0;

        do{
            states = 0;
            found = false;
            do{
                if(tautomata.getTransition(tautomata.getState(actState), tautomata.getState(states)) != null)
                    if(tautomata.getTransition(tautomata.getState(actState), tautomata.getState(states)).getLabel() == s.charAt(index)){
                        found = true;
                        actState = states;
                    }
                states++;
            }while(states < tautomata.getSize()&&(!found));
            index++;
        }while((index < s.length())&&(found));

        if(!(tautomata.getState(actState).getAcceptation())&&(found))
            found = false;
        
        return found;
    }
}
